package com.example.cloud.provider.payment.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.cloud.entities.entity.Payment;
import com.example.cloud.entities.utils.PageQuery;
import com.example.cloud.entities.utils.SimpleMessage;
import com.example.cloud.provider.payment.mapper.PaymentMapper;
import com.example.cloud.provider.payment.service.IPaymentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;


/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author frank
 * @since 2020-10-18
 */
@Service
public class PaymentServiceImpl extends ServiceImpl<PaymentMapper, Payment> implements IPaymentService {

    @Autowired
    private PaymentMapper paymentMapper;

    @Override
    public SimpleMessage deleteById(int id) {
        Payment payment = paymentMapper.selectById(id);
        // payment.setIsDelete(true);
        // payment.setModifyTime(new Timestamp(new Date().getTime()));
        int i = paymentMapper.updateById(payment );
        if (i > 0) {
            return SimpleMessage.info("删除成功！");
        }
        return SimpleMessage.info("删除失败！");
    }

    @Override
    public SimpleMessage queryByPage(PageQuery pageQuery) {
        Map queryMap = new HashMap();
        QueryWrapper<Payment> queryWrapper = new QueryWrapper<Payment>();
        if (StringUtils.isNotBlank(pageQuery.getFilter())) {
            // 处理查询条件
            queryMap = pageQuery.convertFilterToMap();
            // queryWrapper.lambda().like(Payment::getName, queryMap.get("name"));
        }

        // queryWrapper.lambda().eq(Payment::getIsDelete, 0);
        queryWrapper.orderByDesc("id");
        Page<Payment> page = new Page<Payment>(pageQuery.getPage(), pageQuery.getSize());
        IPage<Payment> iPage = paymentMapper.selectPage(page, queryWrapper);

        return SimpleMessage.info("列表" , iPage);
    }

}
